<?php
autoLoader();

$mid 	= ( ( true == isset( $_GET['mid'] ) && true == valStr( $_GET['mid'] ) ) ? $_GET['mid'] : NULL );
$smid 	= ( ( true == isset( $_GET['smid'] ) && true == valStr( $_GET['smid'] ) ) ? $_GET['smid'] : NULL );
$emp_id = ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) && true == valStr( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : NULL;

	$objPatient 	= new BasePatients();
	$objPatients 	= new Patients();
	$objCasePaper 	= new CasePapers();
	
	$objPatientNote = new PatientNotes();
	
	if( true == isset( $_GET['patient_id'] ) && true == valStr( $_GET['patient_id'] ) ) {
		$intPatientId = (int) $_GET['patient_id'];
	
		$objPatient 	= $objPatients->fetchPatientsById( $intPatientId );
	}
	
	if( true == isset( $_GET['patient_note_id'] ) && true == valStr( $_GET['patient_note_id'] ) ) {
		$intPatientNoteId = (int) $_GET['patient_note_id'];
	
		$objPatientNote = $objPatientNote->fetchPatientNotesById( $intPatientNoteId );
	}
?>
<div style="margin-top:5px; margin-bottom: 10px;">
	<?php
		if( true == valObj( $objPatient, 'BasePatients' ) ) {
			echo '<input type="button" value="Add New Note" name="add_yellow_pages" onClick="addNewNote();" class="btn btn-primary" />&nbsp;&nbsp;';
			echo '<input type="button" value="View Yellow Pages" name="yellow_pages" onClick="viewAllNotes();" class="btn btn-primary" />';
		}
	?>
</div>

<div style="border-style: solid; display: block;">
	<div style="padding: 2px;display: none;margin:5px 5px 0px 5px;" class="alert alert-success" id="note_success_display">
		<img alt="note_insert_success Found with info.." src="images/ok.png" width="20" height="20">
		<label id='note_insert_success'></label>
	</div>
	
	<div style="padding: 2px;display: none;margin:5px 5px 0px 5px;" class="alert alert-danger" id="note_failed_display">
		<img alt="Patient Found with info.." src="images/close.png" width="20" height="20">
		<label id='note_insert_failed'></label>
	</div>
	
	<div style="clear: both;"></div>

	<form action="#" name="insert_yellow_page" id="insert_yellow_page" method="post" >
		<table width="100%" cellspacing="0" cellpadding="3" class="table table-striped table-bordered table-hover dataTable no-footer">
			<tr>
				<td>Note:-</td>
				<td>Medician:-</td>
			</tr>
			<tr>
				<?php
					$strNote = $strMedicalDetails = '';
					
					if( true == valObj( $objPatientNote, 'BasePatientNotes' ) ) {
						$strNote = $objPatientNote->getDescription();
						$strMedicalDetails = $objPatientNote->getMedicalDetails();
					}
				?>
				<td>
					<textarea rows="5" cols="45" name="note" id="note" placeholder="Add what need to taken care for this patient..."><?php echo $strNote; ?></textarea>
				</td>
				<td>
					<textarea rows="5" cols="45" name="medician_description" id="medician_description" placeholder="Add medical details needs to give the patient..."><?php echo $strMedicalDetails; ?></textarea>
				</td>
			</tr>
		</table>
	<div style="text-align: center;">
		<?php
			if( true == isset( $_GET['patient_note_id'] ) && true == valStr( $_GET['patient_note_id'] ) && true == valObj( $objPatientNote, 'BasePatientNotes' ) ) { ?>
				<input type="hidden" name="operation" id="operation" value="update" />
				<input type="button" name="Submit" id="submit" value="UPDATE" class="btn btn-primary" onclick="insertYellowPage();" />
				<a href="#"><input type="button" name="cancel" id="cancel" class="btn btn-primary" value="Cancle" onclick="viewAllNotes();" ></a>
		<?php 	} else { ?>
				<input type="hidden" name="operation" id="operation" value="insert" />
				<input type="button" name="Submit" id="submit" value="Add Note" class="btn btn-primary" onclick="insertYellowPage();" />
				<input type="button" name="cancel" id="cancel" value="Cancel" class="btn btn-primary" onclick="viewAllNotes();" />
		<?php } ?>
		<input type="hidden" name="patient_id" value="<?php if( true == isset( $_GET['patient_id'] ) && true == valStr( $_GET['patient_id'] ) ) echo $_GET['patient_id']; ?>" />
		<input type="hidden" name="case_paper_id" value="<?php if( true == isset( $_GET['case_paper_id'] ) && true == valStr( $_GET['case_paper_id'] ) ) echo $_GET['case_paper_id']; ?>" />
		<input type="hidden" name="patient_note_id" value="<?php if( true == isset( $_GET['patient_note_id'] ) && true == valStr( $_GET['patient_note_id'] ) ) echo $_GET['patient_note_id']; ?>" />
		<a id="print_opd_form" style="display: none;" href="modules.php?file=patient_admission&type=print&mid=<?php echo $mid;?>&smid=<?php echo $smid;?>"><input type="button" name="print" id="print" class="btn btn-primary" value="PRINT"></a>
	</div>
	
	</form>
</div>

<script>
	function insertYellowPage() {
		var strNote = $('#note').val();
		if( strNote.length <= 0 ) {
			alert( 'Please enter the note details.' );
			return false;
		}
		
		var postData = $('#insert_yellow_page').serializeArray();

		$strUrl = "modules.php?file=insert_yellow_page&type=insert";
	
		$.ajax({
			url: $strUrl,
			type: "post",
			data: postData,
			beforeSend: function() {
				$("#wait").css("display","block");
				$('.col-lg-10').css("display","none");
			},
			success: function( returnData ) {
				strCustomerData = returnData;

				if( 1 == strCustomerData ) {

					$('#note_insert_success').html( 'Note details inserted Or updated successfully.' );
					$('#note_success_display').css( 'display', 'block' );
					$('#note_failed_display').css( 'display', 'none' );
				} else {
					$('#note_failed_display').css( 'display', 'block' );
					$('#note_insert_failed').html( 'Failed to Insert/Update Note details.' );

					$('#note_success_display').css( 'display', 'none' );
				}

				$("#wait").css("display","none");
				$('.col-lg-10').css("display","block");
			},
			error:function(){
				alert( "! Patient not found with provided information, Please check entered data of patient." );
			}
		});
	}
</script>